//
//  FitHeader.h
//  可可旅行
//
//  Created by dllo on 15/9/30.
//  Copyright © 2015年 直到世界的尽头. All rights reserved.
//
#import <UIKit/UIKit.h>

#ifndef FitHeader_h
#define FitHeader_h
#pragma mark - 适配宏
//所有坐标相对于(375-667)
#define FitWidth ([UIScreen mainScreen].bounds.size.width / 375)
#define FitHeight ([UIScreen mainScreen].bounds.size.height / 667)

#define ScreenWidth [UIScreen mainScreen].bounds.size.width
#define ScreenHeight [UIScreen mainScreen].bounds.size.height

#define ContentTextSize 30
#define FontName @"Zapfino"

/**同行*/
#define SameRow YES
/**同列*/
#define SameColumn NO

/*第一种:单独对常数的处理,注:常量要不全部单独处理,要不整合之后处理*/
#define FitConstant_XorWidth(x) (x)*FitWidth
#define FitConstant_YorHeight(y) (y)*FitHeight

#define GViewX(view) view.frame.origin.x
#define GViewY(view) view.frame.origin.y
#define GViewWidth(view) view.frame.size.width
#define GViewHeight(view) view.frame.size.height

#define FitFont [[NSUserDefaults standardUserDefaults] integerForKey:@"fitFont"]

//得到一个适配好的rect(仅限绝对坐标, 相对坐标使用CGRectMake, 额外加的数值须乘以FitWidth)
/**限绝对坐标*/
CG_INLINE CGRect
FitRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height)
{
    CGRect rect;
    rect.origin.x = x * FitWidth; rect.origin.y = y * FitHeight;
    rect.size.width = width * FitWidth;
    rect.size.height = height * FitHeight;
    return rect;
}

/**限wight, height为计算过的坐标*/
CG_INLINE CGRect
FitPointMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height)
{
    CGRect rect;
    rect.origin.x = x * FitWidth; rect.origin.y = y * FitHeight;
    rect.size.width = width;
    rect.size.height = height;
    return rect;
}

/**限x, y为计算过的坐标*/
CG_INLINE CGRect
FitMake(CGFloat x,CGFloat X, CGFloat y, CGFloat Y, CGFloat width, CGFloat height)
{
    CGRect rect;
    rect.origin.x = x + X * FitWidth; rect.origin.y = y + Y * FitHeight;
    rect.size.width = width * FitWidth;
    rect.size.height = height * FitHeight;
    return rect;
}

/**经过适配的边缘距离*/
UIKIT_STATIC_INLINE UIEdgeInsets FitEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right) {
    UIEdgeInsets insets = {top * FitHeight, left * FitWidth, bottom * FitHeight, right * FitWidth};
    return insets;
}

/**相对设置一个新的控件的位置(大小相同)
 * dirction表示与上一控件的相对关系(SameColumn-同列 SameRow -同行)
 */
CG_INLINE CGRect
FitRelativeRectMake(CGRect rect, CGFloat x, CGFloat y, CGFloat width, CGFloat height, bool dirction)
{
    CGFloat lastWidth = 0;
    CGFloat lastHeight = 0;
    dirction ? (lastWidth = rect.size.width): (lastHeight = rect.size.height);
    rect.origin.x = rect.origin.x + x * FitWidth + lastWidth;
    rect.origin.y = rect.origin.y + y * FitHeight +lastHeight;
    rect.size.width = width * FitWidth;
    rect.size.height = height * FitHeight;
    return rect;
}

/**相对设置一个新的控件的位置
 * dirction表示与上一控件的相对关系(SameColumn-同列 SameRow -同行)
 */
CG_INLINE CGRect
FitPointRectMake(CGRect rect, CGFloat x, CGFloat y, CGFloat width, CGFloat height, bool dirction)
{
    CGFloat lastWidth = 0;
    CGFloat lastHeight = 0;
    dirction ? (lastWidth = rect.size.width): (lastHeight = rect.size.height);
    rect.origin.x = rect.origin.x + x * FitWidth + lastWidth;
    rect.origin.y = rect.origin.y + y * FitHeight +lastHeight;
    rect.size.width = width * FitWidth;
    rect.size.height = height * FitHeight;
    return rect;
}

#endif /* FitHeader_h */
